Hi everyone! I'm currently trying to figure out how to check whether the links in a module were pre-existing in the saved current baseline or were created in the unsaved current session. My current code determines the last saved date of the module and compares it to the link's "Created On" attribute. Unfortunately the "Created On" attribute does not provide a timestamp, only day/month/year. Therefore the comparison gives me false positives on the off chance I created the link earlier in the day, saved it, and then performed a check later in the day on an unsaved current session. Any help would be appreciated. Thanks! Dan Chen - Tue Oct 08 16:09:02 EDT 2019 |
Re: Determine whether Link was created in unsaved current session You could loop through history,
A code snippet to get you going...
History h
for h in current Object do
{
if ( h.type == createLink ) print h.date
}
|
Re: Determine whether Link was created in unsaved current session morast - Wed Oct 09 03:16:22 EDT 2019 You could loop through history,
A code snippet to get you going...
History h
for h in current Object do
{
if ( h.type == createLink ) print h.date
}
Or maybe this could be useful...
Link l
for l in (current Object) -> "*" do
{
print lastModifiedTime(l)
}
|
Re: Determine whether Link was created in unsaved current session morast - Wed Oct 09 03:16:22 EDT 2019 You could loop through history,
A code snippet to get you going...
History h
for h in current Object do
{
if ( h.type == createLink ) print h.date
}
Thanks for the reply morast. If I understand you correctly, this snippet works because it only looks through the unsaved current session history rather than the entire history of the object? Therefore, the only history entries that will be found would be unsaved current changes? |
Re: Determine whether Link was created in unsaved current session Dan Chen - Wed Oct 09 08:06:09 EDT 2019 Thanks for the reply morast. If I understand you correctly, this snippet works because it only looks through the unsaved current session history rather than the entire history of the object? Therefore, the only history entries that will be found would be unsaved current changes? No, it will look through all history (in current, older history is stored in baselines). The point was that you will get the timestamp for the link Creation that you asked for. You still have to compare that timestamp with something. Hope that helps. |
Re: Determine whether Link was created in unsaved current session morast - Wed Oct 09 08:15:18 EDT 2019 No, it will look through all history (in current, older history is stored in baselines). The point was that you will get the timestamp for the link Creation that you asked for. You still have to compare that timestamp with something. Hope that helps. Got it, that's my problem, I was testing it on some objects I had and it wasn't returning any link history even though there were definitely links on the object, but it was because it was stored in an older baseline. Thx Morast! |
Re: Determine whether Link was created in unsaved current session Dan Chen - Wed Oct 09 08:21:50 EDT 2019 Got it, that's my problem, I was testing it on some objects I had and it wasn't returning any link history even though there were definitely links on the object, but it was because it was stored in an older baseline. Thx Morast! I just realized I didn't take the complete problem into consideration. The link timestamp does not help very much if you don't have the timestamp for when the module was last saved. From your question, I assumed you already solved that? Hopefully you have and maybe can share the solution? Otherwise I'm sorry to say I'm not sure how get the timestamp of the latest save. :-( |
Re: Determine whether Link was created in unsaved current session morast - Wed Oct 09 09:03:03 EDT 2019 I just realized I didn't take the complete problem into consideration. The link timestamp does not help very much if you don't have the timestamp for when the module was last saved. From your question, I assumed you already solved that? Hopefully you have and maybe can share the solution? Otherwise I'm sorry to say I'm not sure how get the timestamp of the latest save. :-( I got the last saved date with the following code. It's a bit clunky, but does what I need it to do. There might be cases I'm not accounting for though...
Module m = current Module
Object o
History h
Date lastSavedDate
int tempSessNo = 0, lastSavedSession = 0
Date tempSessDate
Skip skSessions = create
if (unsaved(m))
{
// create a skip list of sessions associated with the date of the last entry for that session
for h in m do {
if((find(skSessions, h.sessionNo, tempSessDate)) and (tempSessDate < h.date))
delete(skSessions, h.sessionNo)
put(skSessions, h.sessionNo, h.date)
}
delete(skSessions, h.sessionNo) // remove the history entry associated with the current session of the unsaved module
// sets lastSavedDate to the date of the last session
for tempSessDate in skSessions do{
tempSessNo = (int key skSessions)
if(tempSessNo < lastSavedSession) continue
if(tempSessDate == lastModifiedTime(m)) continue
lastSavedSession = tempSessNo
lastSavedDate = tempSessDate
}
delete(skSessions)
skSessions = null
}
I then used the following code which I generated from the help you provided to determine which of the outlinks were from the current unsaved session:
Object o = current Object
Link oLnk
History h
for oLnk in all(o->"*") do
{
if (unsaved(m) and (lastModifiedTime(oLnk) >= lastSavedDate))
{
for h in o do
{
if (h.type != createLink) continue
if ((h.targetVersion == targetVersion(oLnk)) and
(h.targetAbsNo == targetAbsNo(oLnk)) and
(h.date > lastSavedDate))
{
(do something...)
}
}
}
}
|
Re: Determine whether Link was created in unsaved current session Dan Chen - Wed Oct 09 09:12:49 EDT 2019 I got the last saved date with the following code. It's a bit clunky, but does what I need it to do. There might be cases I'm not accounting for though...
Module m = current Module
Object o
History h
Date lastSavedDate
int tempSessNo = 0, lastSavedSession = 0
Date tempSessDate
Skip skSessions = create
if (unsaved(m))
{
// create a skip list of sessions associated with the date of the last entry for that session
for h in m do {
if((find(skSessions, h.sessionNo, tempSessDate)) and (tempSessDate < h.date))
delete(skSessions, h.sessionNo)
put(skSessions, h.sessionNo, h.date)
}
delete(skSessions, h.sessionNo) // remove the history entry associated with the current session of the unsaved module
// sets lastSavedDate to the date of the last session
for tempSessDate in skSessions do{
tempSessNo = (int key skSessions)
if(tempSessNo < lastSavedSession) continue
if(tempSessDate == lastModifiedTime(m)) continue
lastSavedSession = tempSessNo
lastSavedDate = tempSessDate
}
delete(skSessions)
skSessions = null
}
I then used the following code which I generated from the help you provided to determine which of the outlinks were from the current unsaved session:
Object o = current Object
Link oLnk
History h
for oLnk in all(o->"*") do
{
if (unsaved(m) and (lastModifiedTime(oLnk) >= lastSavedDate))
{
for h in o do
{
if (h.type != createLink) continue
if ((h.targetVersion == targetVersion(oLnk)) and
(h.targetAbsNo == targetAbsNo(oLnk)) and
(h.date > lastSavedDate))
{
(do something...)
}
}
}
}
Hmmm, I'm not sure about this. I don't think you get a new session number when you save a module. You are still in the same session. Sorry if I confuse things. Maybe I just don't understand what you want to do. Feel free to disregard this comment. |
Re: Determine whether Link was created in unsaved current session morast - Fri Oct 11 06:40:07 EDT 2019 Hmmm, I'm not sure about this. I don't think you get a new session number when you save a module. You are still in the same session. Sorry if I confuse things. Maybe I just don't understand what you want to do. Feel free to disregard this comment. You're right! I didn't even think of the case where they make changes, save, and then rather than re-opening and making new changes, they just continue making changes in same session. Not sure how exactly to handle that case... |